package com.wc.算法提高课.E第五章_数学知识.组合计数.牡牛和牝牛;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/7 0:15
 * @description https://www.acwing.com/problem/content/1309/
 */
public class Main {
    /**
     * 思路：<p>
     * dp的思想：f[i]表示第i位置为牡牛的数量, 然后后面都是牝牛
     * f[i] = f[0] + f[1] + ... + f[i - k - 1], 前面至少要间隔 k 个牝牛才行
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, P = 5000011;
    // f[i] 表示第i位置为牡牛的数量, s[i] = f[0] + ... + f[i]
    static int[] f = new int[N], s = new int[N];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        f[0] = s[0] = 1;
        for (int i = 1; i <= n; i++) {
            f[i] = s[Math.max(0, i - k - 1)];
            s[i] = (s[i - 1] + f[i]) % P;
        }
        out.println(s[n]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
